package filter;

import java.util.ArrayList;

import models.Post;

/**
 * Classe che permette il filtraggio di post a seconda del nome del loro autore.
 * 
 */
public class FilterPostsByAuthorName implements IFilterPosts {
	private final String authorName;

	public FilterPostsByAuthorName(String authorName) {
		if (authorName == null) {
			this.authorName = "";
		} else {
			this.authorName = authorName;
		}
	}

	@Override
	public ArrayList<Post> applyFilter(ArrayList<Post> postList) {
		final ArrayList<Post> resultPostList = new ArrayList<Post>();

		for (final Post post : postList) {
			if (post.getAuthor().getFullName().toLowerCase()
					.contains(authorName.toLowerCase())) {
				resultPostList.add(post);
			}
		}

		return resultPostList;
	}

}
